package spring.lottery.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import spring.lottery.common.pojo.ResponseMode;
import spring.lottery.controller.param.CreateActivityParam;
import spring.lottery.server.ActivitiesServer;
import spring.lottery.server.dto.ActivityListDto;
import spring.lottery.server.dto.GetUserListDto;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("activity")
public class ActivitiesController {

    @Autowired
    ActivitiesServer activitiesServer;

    /**
     * 查询人员列表
     */
    @RequestMapping("base-user/find-list")
    public ResponseMode findUserList(){
        List<GetUserListDto> userList = activitiesServer.findUserList();

        log.info("ActivitiesController.findUserList 返回的结果: {}",userList);

        return ResponseMode.success(userList);
    }

    /**
     * Json
     * {"activityName":"tesy",
     * "description":"rr",
     * ----
     * "activityPrizeList": [{"prizeId":71,"prizeAmount":1,"prizeTiers":"SECOND_PRIZE"}
     * ,{"prizeId":70,"prizeAmount":1,"prizeTiers":"FIRST_PRIZE"}],
     * ----
     * "activityUserList":[{"userId":55,"userName":"hadage"},
     * {"userId":56,"userName":"hhh"},{"userId":57,"userName":"cool"}]}
     */
    @RequestMapping("create")
    public ResponseMode createActivity(@Valid @RequestBody CreateActivityParam param) {
        log.info("收到请求 ActivitiesController.createActivity: {}", param);

        Long activity = activitiesServer.createActivity(param);

        log.info("ActivitiesController.createActivity 返回的结果: {}", activity);

        return ResponseMode.success(activity);
    }

    /**
     * activity/find-list
     */
    @RequestMapping("find-list")
    public ResponseMode findActivityList(String identity) {
        log.info("收到请求 ActivitiesController.findActivityList: {}", identity);

        ActivityListDto activityList = activitiesServer.findActivityList();

        log.info("ActivitiesController.findActivityList 返回的结果: {} ", activityList);

        return ResponseMode.success(activityList);
    }

}
